package SellCar.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;


import SellCar.dao.sell.SellMapper;
import SellCar.dao.sell.impl.SellMapperImpl;
import SellCar.service.SellBiz;
import SellCar.service.impl.SellBizImpl;

public class SellServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			this.doPost(request, response);
	}
		Logger logger = Logger.getLogger(SellServlet.class);
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			response.setContentType("text/html;charset=utf-8");
			PrintWriter out = response.getWriter();
			HttpSession session = request.getSession();
			request.setCharacterEncoding("UTF-8");
			response.setCharacterEncoding("UTF-8");
			
			SellBiz biz = new SellBizImpl();
			//String opr = request.getParameter("opr");
			//if("sell".equals(opr)){
			String carName = request.getParameter("carName");
			String year = request.getParameter("year");
			Integer price =Integer.parseInt(request.getParameter("price"));
			String particulars = request.getParameter("particulars");
			String image = request.getParameter("image");
			System.out.println(carName);
			Integer count = biz.addInfo(carName, year, price, particulars, image);
			//logger.debug(carName+year+"count = "+count);
				if(count>0){
					biz.showSellInfo(carName, year, price, particulars, image);
					request.getRequestDispatcher("showSell2.jsp").forward(request, response);
				}else{
					response.sendRedirect("Error.jsp");
				}
			//}
			

	}

}
